﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TravelManagement
{
    public partial class ChangePassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnChangePassword_Click(object sender, EventArgs e)
        {
            try
            {
                string userName = Page.User.Identity.Name;
                string oldPassword = txtOldPassword.Text;
                string newPassword = txtPassword.Text;

                using (TSPGMapsDBContainer entities = new TSPGMapsDBContainer())
                {
                    var user = (from userRow in entities.Users
                                where userRow.UserName == userName && userRow.Password == oldPassword
                                select userRow).SingleOrDefault();

                    if (user != null)
                    {
                        user.Password = newPassword;

                        entities.SaveChanges();
                        lblPasswordChanged.Visible = true;
                    }
                    else
                    {
                        lblPasswordChanged.Text = "Wrong inputs.";
                        lblPasswordChanged.Visible = true;
                    }

                }
            }
            catch (Exception ex)
            {

            }


        }
    }
}